# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test14_6
# Description:  例14.6
# Author:       ASUS
# Date:         2019/4/17
#-------------------------------------------------------------------------------


import json
class Product:
    def __init__(self,name,price,count):
        self.name = name
        self.price = price
        self.count = count
#用于将product类的实例转换为字典的回调函数
def product2Dict(ojb):
    return {
        'name':ojb.name,
        'price':ojb.price,
        'count':ojb.count
    }
product = Product('特斯拉',100000,20)
#ensure_ascii关键字参数的值设为False，可以让返回的json字符串正常显示中文
jsonStr = json.dumps(product,default=product2Dict,ensure_ascii=False)
print(jsonStr)

